﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;

namespace DALL.Progect
{
   public class T_PUB_FILEATTRIBUTE
    {
        public T_PUB_FILEATTRIBUTE()
        { }
        #region  Method
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Model.Progect.T_PUB_FILEATTRIBUTE model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_PUB_FILEATTRIBUTE(");
            strSql.Append("FILE_ID,AREA,CELEBRATION_TYPE,NEWSCHOOL,MYXILAI,STYLE,COLOR,DRESS_TYPE,DRESS_LEVEL,DRESS_COLOR,DRESS_PRICE,WEDDING_COLOR,WEDDING_PRICE,WEDDING_MONTH,WEDDING_STYLE,MATERIAL_STAR,HOTEL_NAME,HOTEL_DESK_NUM,HOTEL_STYLE,HOTEL_SPECIFICATION,HOTEL_LOCATION,MAX_PRICE,MIN_PRICE,PROJECT_TYPE)");

            strSql.Append(" values (");
            strSql.Append("@FILE_ID,@AREA,@CELEBRATION_TYPE,@NEWSCHOOL,@MYXILAI,@STYLE,@COLOR,@DRESS_TYPE,@DRESS_LEVEL,@DRESS_COLOR,@DRESS_PRICE,@WEDDING_COLOR,@WEDDING_PRICE,@WEDDING_MONTH,@WEDDING_STYLE,@MATERIAL_STAR,@HOTEL_NAME,@HOTEL_DESK_NUM,@HOTEL_STYLE,@HOTEL_SPECIFICATION,@HOTEL_LOCATION,@MAX_PRICE,@MIN_PRICE,@PROJECT_TYPE)");
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "FILE_ID", DbType.String, model.FILE_ID);
            db.AddInParameter(dbCommand, "AREA", DbType.String, model.AREA);
            db.AddInParameter(dbCommand, "CELEBRATION_TYPE", DbType.String, model.CELEBRATION_TYPE);
            db.AddInParameter(dbCommand, "NEWSCHOOL", DbType.String, model.NEWSCHOOL);
            db.AddInParameter(dbCommand, "MYXILAI", DbType.String, model.MYXILAI);
            db.AddInParameter(dbCommand, "STYLE", DbType.String, model.STYLE);
            db.AddInParameter(dbCommand, "COLOR", DbType.String, model.COLOR);
            db.AddInParameter(dbCommand, "DRESS_TYPE", DbType.String, model.DRESS_TYPE);
            db.AddInParameter(dbCommand, "DRESS_LEVEL", DbType.String, model.DRESS_LEVEL);
            db.AddInParameter(dbCommand, "DRESS_COLOR", DbType.String, model.DRESS_COLOR);
            db.AddInParameter(dbCommand, "DRESS_PRICE", DbType.String, model.DRESS_PRICE);
            db.AddInParameter(dbCommand, "WEDDING_COLOR", DbType.String, model.WEDDING_COLOR);
            db.AddInParameter(dbCommand, "WEDDING_PRICE", DbType.String, model.WEDDING_PRICE);
            db.AddInParameter(dbCommand, "WEDDING_MONTH", DbType.String, model.WEDDING_MONTH);
            db.AddInParameter(dbCommand, "WEDDING_STYLE", DbType.String, model.WEDDING_STYLE);
            db.AddInParameter(dbCommand, "MATERIAL_STAR", DbType.String, model.MATERIAL_STAR);
            db.AddInParameter(dbCommand, "HOTEL_NAME", DbType.String, model.HOTEL_NAME);
            db.AddInParameter(dbCommand, "HOTEL_DESK_NUM", DbType.String, model.HOTEL_DESK_NUM);
            db.AddInParameter(dbCommand, "HOTEL_STYLE", DbType.String, model.HOTEL_STYLE);
            db.AddInParameter(dbCommand, "HOTEL_SPECIFICATION", DbType.String, model.HOTEL_SPECIFICATION);
            db.AddInParameter(dbCommand, "HOTEL_LOCATION", DbType.String, model.HOTEL_LOCATION);
            db.AddInParameter(dbCommand, "MAX_PRICE", DbType.Double, model.MAX_PRICE);
            db.AddInParameter(dbCommand, "MIN_PRICE", DbType.Double, model.MIN_PRICE);
            db.AddInParameter(dbCommand, "PROJECT_TYPE", DbType.String, model.PROJECT_TYPE);
            int result;
            object obj = db.ExecuteScalar(dbCommand);
            if (!int.TryParse(obj.ToString(), out result))
            {
                return false;
            }
            return true;
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.Progect.T_PUB_FILEATTRIBUTE model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_PUB_FILEATTRIBUTE set ");
            strSql.Append("AREA=@AREA,");
            strSql.Append("CELEBRATION_TYPE=@CELEBRATION_TYPE,");
            strSql.Append("NEWSCHOOL=@NEWSCHOOL,");
            strSql.Append("MYXILAI=@MYXILAI,");
            strSql.Append("STYLE=@STYLE,");
            strSql.Append("COLOR=@COLOR,");
            strSql.Append("DRESS_TYPE=@DRESS_TYPE,");
            strSql.Append("DRESS_LEVEL=@DRESS_LEVEL,");
            strSql.Append("DRESS_COLOR=@DRESS_COLOR,");
            strSql.Append("DRESS_PRICE=@DRESS_PRICE,");
            strSql.Append("WEDDING_COLOR=@WEDDING_COLOR,");
            strSql.Append("WEDDING_PRICE=@WEDDING_PRICE,");
            strSql.Append("WEDDING_MONTH=@WEDDING_MONTH,");
            strSql.Append("WEDDING_STYLE=@WEDDING_STYLE,");
            strSql.Append("MATERIAL_STAR=@MATERIAL_STAR,");
            strSql.Append("HOTEL_NAME=@HOTEL_NAME,");
            strSql.Append("HOTEL_DESK_NUM=@HOTEL_DESK_NUM,");
            strSql.Append("HOTEL_STYLE=@HOTEL_STYLE,");
            strSql.Append("HOTEL_SPECIFICATION=@HOTEL_SPECIFICATION,");
            strSql.Append("HOTEL_LOCATION=@HOTEL_LOCATION,");
            strSql.Append("MAX_PRICE=@MAX_PRICE,");
            strSql.Append("MIN_PRICE=@MIN_PRICE,");
            strSql.Append("PROJECT_TYPE=@PROJECT_TYPE");
            strSql.Append(" where FILE_ID=@FILE_ID ");
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "FILE_ID", DbType.String, model.FILE_ID);
            db.AddInParameter(dbCommand, "AREA", DbType.String, model.AREA);
            db.AddInParameter(dbCommand, "CELEBRATION_TYPE", DbType.String, model.CELEBRATION_TYPE);
            db.AddInParameter(dbCommand, "NEWSCHOOL", DbType.String, model.NEWSCHOOL);
            db.AddInParameter(dbCommand, "MYXILAI", DbType.String, model.MYXILAI);
            db.AddInParameter(dbCommand, "STYLE", DbType.String, model.STYLE);
            db.AddInParameter(dbCommand, "COLOR", DbType.String, model.COLOR);
            db.AddInParameter(dbCommand, "DRESS_TYPE", DbType.String, model.DRESS_TYPE);
            db.AddInParameter(dbCommand, "DRESS_LEVEL", DbType.String, model.DRESS_LEVEL);
            db.AddInParameter(dbCommand, "DRESS_COLOR", DbType.String, model.DRESS_COLOR);
            db.AddInParameter(dbCommand, "DRESS_PRICE", DbType.String, model.DRESS_PRICE);
            db.AddInParameter(dbCommand, "WEDDING_COLOR", DbType.String, model.WEDDING_COLOR);
            db.AddInParameter(dbCommand, "WEDDING_PRICE", DbType.String, model.WEDDING_PRICE);
            db.AddInParameter(dbCommand, "WEDDING_MONTH", DbType.String, model.WEDDING_MONTH);
            db.AddInParameter(dbCommand, "WEDDING_STYLE", DbType.String, model.WEDDING_STYLE);
            db.AddInParameter(dbCommand, "MATERIAL_STAR", DbType.String, model.MATERIAL_STAR);
            db.AddInParameter(dbCommand, "HOTEL_NAME", DbType.String, model.HOTEL_NAME);
            db.AddInParameter(dbCommand, "HOTEL_DESK_NUM", DbType.String, model.HOTEL_DESK_NUM);
            db.AddInParameter(dbCommand, "HOTEL_STYLE", DbType.String, model.HOTEL_STYLE);
            db.AddInParameter(dbCommand, "HOTEL_SPECIFICATION", DbType.String, model.HOTEL_SPECIFICATION);
            db.AddInParameter(dbCommand, "HOTEL_LOCATION", DbType.String, model.HOTEL_LOCATION);
            db.AddInParameter(dbCommand, "MAX_PRICE", DbType.Double, model.MAX_PRICE);
            db.AddInParameter(dbCommand, "MIN_PRICE", DbType.Double, model.MIN_PRICE);
            db.AddInParameter(dbCommand, "PROJECT_TYPE", DbType.String, model.PROJECT_TYPE);
            int rows = db.ExecuteNonQuery(dbCommand);

            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string FILE_ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_PUB_FILEATTRIBUTE ");
            strSql.Append(" where FILE_ID=@FILE_ID ");
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "FILE_ID", DbType.String, FILE_ID);
            int rows = db.ExecuteNonQuery(dbCommand);

            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Progect.T_PUB_FILEATTRIBUTE GetModel(string FILE_ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FILE_ID,AREA,CELEBRATION_TYPE,NEWSCHOOL,MYXILAI,STYLE,COLOR,DRESS_TYPE,DRESS_LEVEL,DRESS_COLOR,DRESS_PRICE,WEDDING_COLOR,WEDDING_PRICE,WEDDING_MONTH,WEDDING_STYLE,MATERIAL_STAR,HOTEL_NAME,HOTEL_DESK_NUM,HOTEL_STYLE,HOTEL_SPECIFICATION,HOTEL_LOCATION,MAX_PRICE,MIN_PRICE,PROJECT_TYPE from T_PUB_FILEATTRIBUTE ");
            strSql.Append(" where FILE_ID=@FILE_ID ");
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "FILE_ID", DbType.String, FILE_ID);
            Model.Progect.T_PUB_FILEATTRIBUTE model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
            }
            return model;
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FILE_ID,AREA,CELEBRATION_TYPE,NEWSCHOOL,MYXILAI,STYLE,COLOR,DRESS_TYPE,DRESS_LEVEL,DRESS_COLOR,DRESS_PRICE,WEDDING_COLOR,WEDDING_PRICE,WEDDING_MONTH,WEDDING_STYLE,MATERIAL_STAR,HOTEL_NAME,HOTEL_DESK_NUM,HOTEL_STYLE,HOTEL_SPECIFICATION,HOTEL_LOCATION,MAX_PRICE,MIN_PRICE,PROJECT_TYPE ");
            strSql.Append(" FROM T_PUB_FILEATTRIBUTE ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            Database db = DatabaseFactory.CreateDatabase();
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public List<Model.Progect.T_PUB_FILEATTRIBUTE> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FILE_ID,AREA,CELEBRATION_TYPE,NEWSCHOOL,MYXILAI,STYLE,COLOR,DRESS_TYPE,DRESS_LEVEL,DRESS_COLOR,DRESS_PRICE,WEDDING_COLOR,WEDDING_PRICE,WEDDING_MONTH,WEDDING_STYLE,MATERIAL_STAR,HOTEL_NAME,HOTEL_DESK_NUM,HOTEL_STYLE,HOTEL_SPECIFICATION,HOTEL_LOCATION,MAX_PRICE,MIN_PRICE,PROJECT_TYPE ");
            strSql.Append(" FROM T_PUB_FILEATTRIBUTE ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<Model.Progect.T_PUB_FILEATTRIBUTE> list = new List<Model.Progect.T_PUB_FILEATTRIBUTE>();
            Database db = DatabaseFactory.CreateDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
            }
            return list;
        }

        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public Model.Progect.T_PUB_FILEATTRIBUTE ReaderBind(IDataReader dataReader)
        {
            Model.Progect.T_PUB_FILEATTRIBUTE model = new Model.Progect.T_PUB_FILEATTRIBUTE();
            object ojb;
            model.FILE_ID = dataReader["FILE_ID"].ToString();
            model.AREA = dataReader["AREA"].ToString();
            model.CELEBRATION_TYPE = dataReader["CELEBRATION_TYPE"].ToString();
            model.NEWSCHOOL = dataReader["NEWSCHOOL"].ToString();
            model.MYXILAI = dataReader["MYXILAI"].ToString();
            model.STYLE = dataReader["STYLE"].ToString();
            model.COLOR = dataReader["COLOR"].ToString();
            model.DRESS_TYPE = dataReader["DRESS_TYPE"].ToString();
            model.DRESS_LEVEL = dataReader["DRESS_LEVEL"].ToString();
            model.DRESS_COLOR = dataReader["DRESS_COLOR"].ToString();
            model.DRESS_PRICE = dataReader["DRESS_PRICE"].ToString();
            model.WEDDING_COLOR = dataReader["WEDDING_COLOR"].ToString();
            model.WEDDING_PRICE = dataReader["WEDDING_PRICE"].ToString();
            model.WEDDING_MONTH = dataReader["WEDDING_MONTH"].ToString();
            model.WEDDING_STYLE = dataReader["WEDDING_STYLE"].ToString();
            model.MATERIAL_STAR = dataReader["MATERIAL_STAR"].ToString();
            model.HOTEL_NAME = dataReader["HOTEL_NAME"].ToString();
            model.HOTEL_DESK_NUM = dataReader["HOTEL_DESK_NUM"].ToString();
            model.HOTEL_STYLE = dataReader["HOTEL_STYLE"].ToString();
            model.HOTEL_SPECIFICATION = dataReader["HOTEL_SPECIFICATION"].ToString();
            model.HOTEL_LOCATION = dataReader["HOTEL_LOCATION"].ToString();
            ojb = dataReader["MAX_PRICE"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.MAX_PRICE = Convert.ToInt32(ojb);
            }
            ojb = dataReader["MIN_PRICE"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.MIN_PRICE = Convert.ToInt32(ojb);
            }
            model.PROJECT_TYPE = dataReader["PROJECT_TYPE"].ToString();
            return model;
        }

        #endregion  Method
    }
}
